package com.lhd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lhd.mapper.GarbageMapper;
import com.lhd.pojo.Garbage;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.service.GarbageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GarbageServiceImpl implements GarbageService {
    @Autowired
    GarbageMapper garbageMapper;
    @Override
    public List<Garbage> getAll() {
        return garbageMapper.getAll();
    }

    @Override
    public PageBean<Garbage> getWithCondition(Garbage garbage, PageCondition pageCondition) {
        //开启分页查询
        PageHelper.startPage(pageCondition.getPageNum(),pageCondition.getPageSize());
        //查询
       Page<Garbage> page = garbageMapper.getWithCondition(garbage);
       List<Garbage> list = page.getResult();
       return new PageBean<>(page.getTotal(),list);
    }

    @Override
    public void update(Garbage garbage) {
        garbageMapper.update(garbage);
    }

    @Override
    public void add(Garbage garbage) {
        garbageMapper.add(garbage);
    }

    @Override
    public void remove(Integer id) {
        garbageMapper.remove(id);
    }
}
